package com.wecheir.controller;


import com.wecheir.entity.Echarts.LastActivity;
import com.wecheir.entity.LoginData;
import com.wecheir.entity.vo.LoginEchats;
import com.wecheir.service.CreditService;
import com.wecheir.service.LoginDataService;
import com.wecheir.service.UserService;
import com.wecheir.utils.DateUtil;
import com.wecheir.utils.ResponseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * 用户登录后数据的操作controller层
 */
@Controller
@RequestMapping("/app")
public class LoginDataController {

    @Resource
    LoginDataService loginDataService;

    @Resource
    CreditService creditService;

    @Resource
    UserService userService;




    /**
     * 获取最近七天的登录次数
     * @return
     */
    @PostMapping("/datacharts")
    @ResponseBody
    public ResponseUtils datacharts(){
        ResponseUtils responseEntity=new ResponseUtils();
        List<LoginEchats> loginEchatsList=loginDataService.getLoginDataEcharts();

        //取一周的数据
        String[] createDateArray=new String[loginEchatsList.size()];
        int[] dataArray=new int[loginEchatsList.size()];
        LastActivity lastActivity=new LastActivity();//存储最近访问数据的实体

        for (int i=0;i<loginEchatsList.size();i++){
            //获取登录时间
            if(null==loginEchatsList.get(i).getCreateDate()){
                createDateArray[i]="该日期没有访问";
            }else{
                createDateArray[i]= DateUtil.getStringDateShort(loginEchatsList.get(i).getCreateDate());
            }
            dataArray[i]=loginEchatsList.get(i).getCount();
        }
        lastActivity.setCreateDateArray(createDateArray);
        lastActivity.setDataArray(dataArray);
        return ResponseUtils.setSuccess(lastActivity);

    }
}
